package com.agrm.good.mapper;

import com.agrm.model.good.pojo.Good;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodMapper extends BaseMapper<Good> {
    @Update("update good set qty=qty+#{delta} where id=#{goodId}")
    int updateQty(Integer goodId,Integer delta);

    //查询所有秒杀商品(已开启的秒杀活动，且未结束)
    default List<Good> findAllSeckill() {
        LambdaQueryWrapper<Good> qw = Wrappers.lambdaQuery();
        qw.eq(Good::getIsSeckill, true);
        return selectList(qw);
    }
}
